// 模拟数据存储
let users = [
    { id: 1, name: 'Alice',age:20,address:'beijing',date:'2024-01-01' },
    { id: 2, name: 'Bob',age:21,address:'shanghai',date:'2024-01-02' },
    { id: 3, name: 'Charlie',age:22,address:'guangzhou',date:'2024-01-03' },
    { id: 4, name: 'David',age:23,address:'shenzhen',date:'2024-01-04' },
  ];
  
  export const getUsers = async (ctx) => {
    ctx.body = {
      success: true,
      data: users,
      code:200
    };
  };
  
  export const getUserById = async (ctx) => {
    const user = users.find(u => u.id === parseInt(ctx.params.id));
    if (!user) {
      ctx.throw(404, 'User not found');
    }
    ctx.body = {
      success: true,
      data: user,
      code:200
    };
  };
  
  export const createUser = async (ctx) => {
    const { name } = ctx.request.body;
    if (!name) {
      ctx.throw(400, 'Name is required');
    }
    
    const newUser = {
      id: users.length + 1,
      name
    };
    users.push(newUser);
    
    ctx.status = 201;
    ctx.body = {
      success: true,
      data: newUser,
      code:200
    };
  };
  